if exists (select 1 from sysobjects where name = 'del_dienst' and type = 'P')
begin
   drop procedure del_dienst
   print 'Procedure: del_dienst deleted ...'
end
go
create procedure del_dienst(
  @diesntid          int   = 1
)
as
begin
  set nocount on
  
  if exists (select * from Dienstplan where DienstID = @diesntid)
  begin
	  update Dienst
		 set Status = 1  -- 0:Aktiv 1:Nicht Aktiv
	   where DienstID = @diesntid
   end
   else
   begin
	   delete from Dienst where DienstID = @diesntid
   end

end
go
print 'Procedure: del_dienst done ...'
go
grant exec on del_dienst to prsadmins with grant option
go
grant exec on del_dienst to prsusers
go

